package com.burst.reptile.modular.system.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.burst.reptile.framework.aspectj.lang.annotation.Log;
import com.burst.reptile.framework.aspectj.lang.enums.BusinessType;
import com.burst.reptile.framework.web.controller.BaseController;
import com.burst.reptile.framework.web.result.LayuiResult;
import com.burst.reptile.framework.web.result.Result;
import com.burst.reptile.modular.system.entity.SysNotice;
import com.burst.reptile.modular.system.service.ISysNoticeService;

import lombok.RequiredArgsConstructor;

/**
 * <p>
 * 通知公告表 前端控制器
 * </p>
 *
 * @author wujin
 * @since 2020-06-08
 */
@RestController
@RequestMapping("/system/notice")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class SysNoticeController extends BaseController {

	private final ISysNoticeService noticeService;

	/**
	 * 获取通知公告列表
	 */
	@PreAuthorize("@ss.hasPermi('system:notice:list')")
	@GetMapping("/list")
	public LayuiResult<Object> list(SysNotice notice) {
		Page<SysNotice> page = startPage();
		Page<SysNotice> list = noticeService.selectPageNoticeList(page, notice);
		return LayuiResult.success(list.getTotal(), list.getRecords());
	}

	/**
	 * 根据通知公告编号获取详细信息
	 */
	@PreAuthorize("@ss.hasPermi('system:notice:query')")
	@GetMapping(value = "/{noticeId}")
	public Result<Object> getInfo(@PathVariable Long noticeId) {
		return Result.success(noticeService.selectNoticeById(noticeId));
	}

	/**
	 * 新增通知公告
	 */
	@PreAuthorize("@ss.hasPermi('system:notice:add')")
	@Log(title = "通知公告", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	public Result<Object> add(@Validated @RequestBody SysNotice notice) {
		return Result.success(noticeService.insertNotice(notice));
	}

	/**
	 * 修改通知公告
	 */
	@PreAuthorize("@ss.hasPermi('system:notice:edit')")
	@Log(title = "通知公告", businessType = BusinessType.UPDATE)
	@PutMapping("/edit")
	public Result<Object> edit(@Validated @RequestBody SysNotice notice) {
		return Result.success(noticeService.updateNotice(notice));
	}

	/**
	 * 删除通知公告
	 */
	@PreAuthorize("@ss.hasPermi('system:notice:remove')")
	@Log(title = "通知公告", businessType = BusinessType.DELETE)
	@DeleteMapping("/remove/{noticeIds}")
	public Result<Object> remove(@PathVariable Long[] noticeIds) {
		return Result.success(noticeService.deleteNoticeByIds(noticeIds));
	}
}
